package com.nbsaas.boot.project.rest.convert;

import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.project.api.domain.request.ReceiptRequest;
import com.nbsaas.boot.project.data.entity.Project;
import com.nbsaas.boot.project.data.entity.Receipt;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;

/**
 * 收款单请求对象转换成实体对象
 */

public class ReceiptEntityConvert implements Converter<Receipt, ReceiptRequest> {

    @Override
    public Receipt convert(ReceiptRequest source) {
        Receipt result = new Receipt();
        BeanDataUtils.copyProperties(source, result);
        if (source.getCreator() != null) {
            User creator = new User();
            creator.setId(source.getCreator());
            result.setCreator(creator);
        }
        if (source.getProject() != null) {
            Project project = new Project();
            project.setId(source.getProject());
            result.setProject(project);
        }
        return result;
    }
}

